#define _CRT_SECURE_NO_WARNINGS 1

#include "ObjectPool.h"
#include "ConcurrentAlloc.h"


void Alloc1()
{
	for (size_t i = 0; i < 5; i++)
	{
		void* ptr = ConcurrentAlloc(6);
	}
}

void Alloc2()
{
	for (size_t i = 0; i < 5; i++)
	{
		void* ptr = ConcurrentAlloc(7);
	}
}

void TLSTest()
{
	std::thread t1(Alloc1);
	std::thread t2(Alloc2);

	t1.join();
	t2.join();
}

//void TestConcurrentAlloc()
//{
//	//void* p1 = ConcurrentAlloc(6);
//	//void* p2 = ConcurrentAlloc(4);
//	//void* p3 = ConcurrentAlloc(6);
//	//void* p4 = ConcurrentAlloc(7);
//	//void* p5 = ConcurrentAlloc(5);
//	//void* p6 = ConcurrentAlloc(3);
//
//	for (size_t i = 0; i < 1024; ++i)
//	{
//		void* p1 = ConcurrentAlloc(6);
//		cout << p1 << endl;
//	}
//	void* p2 = ConcurrentAlloc(6);
//	cout << p2 << endl;
//}

void TestConcurrentAlloc()
{
	void* p1 = ConcurrentAlloc(6);
	void* p2 = ConcurrentAlloc(4);
	void* p3 = ConcurrentAlloc(6);
	void* p4 = ConcurrentAlloc(7);
	void* p5 = ConcurrentAlloc(5);
	void* p6 = ConcurrentAlloc(3);
	void* p7 = ConcurrentAlloc(3);

	ConcurrentFree(p1);
	ConcurrentFree(p2);
	ConcurrentFree(p3);
	ConcurrentFree(p4);
	ConcurrentFree(p5);
	ConcurrentFree(p6);
	ConcurrentFree(p7);

}

void BigAlloc()
{
	void* p1 = ConcurrentAlloc(257 * 1024);
	ConcurrentFree(p1);

	void* p2 = ConcurrentAlloc(129 * 8 * 1024);
	ConcurrentFree(p2);
}
//int main()
//{
//	//TestObjectPool();
//	//TLSTest();
//	//TestConcurrentAlloc();
//	BigAlloc();
//	return 0;
//}